﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Evpo.ContactData.ViewModel;
using Evpo.ContactData.UI.Tools;

namespace Evpo.ContactData.UI
{
    public partial class LinkedGroup : System.Web.UI.UserControl
    {
        public LinkedGroup()
        {
            IsReadOnly = false;
        }

        #region Handlers


        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Page_PreRender(object sender, EventArgs e)
        {
            if (uiLinkedContacts.Items.Count == 0)
            {
                uiEmply.Visible = true;
            }
            else
            {
                uiEmply.Visible = false;
            }
        }
        #endregion Handlers

        #region Fields
        private ItemInListContainer _contactInListContainer = new ItemInListContainer();
        #endregion Fields

        #region Methods
        internal IEnumerable<int> SeletedContacts()
        {
            foreach (int retVal in _contactInListContainer.SelectedItems(uiLinkedContacts.Items.Cast<Control>(), "uiContactInList"))
                yield return retVal;
        }
        #endregion Methods

        #region Properties
        public List<ContactLink> DataSource
        {
            get
            {
                return (List<ContactLink>)uiLinkedContacts.DataSource;
            }
            set
            {
                uiLinkedContacts.DataSource = value;
            }
        }

        public int ItemCount
        {
            get
            {
                return uiLinkedContacts.Items.Count;
            }
        }

        public bool IsReadOnly
        {
            get;
            set;
        }
        #endregion


    }
}